<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class PLParam
{
    ////////////////////////////////////////
    //Constant.
    ////////////////////////////////////////
    var $PLPARAM_BIN_PATH = "";
    var $PLPARAM_BIN_CRYPT = "pldescmd";
    var $PLPARAM_FIELD_DELEMITER = "";
    var $PLPARAM_VALUE_DELEMITER = "";
	var $PLPARAM_ENCTEXT_SET_FIELD = "resultparam";
	var $PLPARAM_BLANK_STR = "";

    ////////////////////////////////////////
    //internal variables.
    ////////////////////////////////////////
    var $DataParam;
    var $ReceivedDataParam;
   
    //Constructor.
    public function __construct($params)
    {
        $this->PLPARAM_BIN_PATH = $params['doc_root']."/external/payoneq/Lib/";
		// echo "dir=".$this->PLPARAM_BIN_PATH;
    }
    
    function Decrypt($strClientParam)
    {
		$Command = "";
        $Result = "";
        $Command = $this->PLPARAM_BIN_PATH.$this->PLPARAM_BIN_CRYPT." d \"".$strClientParam."\"";
		$Result = exec($Command);
		
        if($Result[0] == '0')
            $this->ReceivedDataParam = substr($Result,1);
        else
            $this->ReceivedDataParam = FALSE;		
    }

	function Encrypt()
    {
        $Command = "";
		$Result = "";
		$Command = $this->PLPARAM_BIN_PATH.$this->PLPARAM_BIN_CRYPT." e \"".$this->DataParam."\"";
//		echo $Command;
		$Result = exec($Command);

		$this->DataParam = substr($Result,1);
		
		return($this->DataParam);
    }
    
    function SetParam($strFieldName, $strFieldValue)
    {
        if($strFieldName==$this->PLPARAM_ENCTEXT_SET_FIELD)
			$this->Decrypt($strFieldValue);
		else
			$this->DataParam .= $this->PLPARAM_FIELD_DELEMITER.$strFieldName.$this->PLPARAM_VALUE_DELEMITER.$strFieldValue;
    }
    
    function GetParam($strFieldName)
    {
		$SearchStr = "";
        $strTmp1 = "";
        $strTmp2 = "";
        $find1pos = 0;
        $find2pos = 0;
        
        $SearchStr = $this->PLPARAM_FIELD_DELEMITER.$strFieldName.$this->PLPARAM_VALUE_DELEMITER;

        if ( ($strTmp1 = stristr($this->ReceivedDataParam, $SearchStr)) == FALSE )
        {
			return ($this->PLPARAM_BLANK_STR);
        }
        else
        {
            $strTmp1 = substr($strTmp1,strlen($SearchStr));
            
			if ( ($strTmp2 = stristr($strTmp1, $this->PLPARAM_FIELD_DELEMITER))== FALSE )
            {
				return(trim($strTmp1));
            }
            else
            {
				if ( strcasecmp($strTmp1,$strTmp2) )
                {
                    $find2pos = strlen($strTmp1)-strlen($strTmp2);
                    return(trim(substr($strTmp1,0,$find2pos)));
                }
                else
                    return("");
            }
        }
    }
}

/* End of file PLParam.php */
/* Location: ./application/libraries/PLParam.php */